﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_hooneyhistu_liige", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedHooneyhistuLiige))]
    public class DetailandmedHooneyhistuLiigeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedHooneyhistuLiige clazz;
        
        public DetailandmedHooneyhistuLiigeSerializer(IDetailandmedHooneyhistuLiige clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.LiikmesuseNr!=null) {
                Writer.WriteStartElement("liikmesuse_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.LiikmesuseNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Pindala!=null) {
                Writer.WriteStartElement("pindala");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Pindala))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaksumaaraLugeja!=null) {
                Writer.WriteStartElement("maksumaara_lugeja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.MaksumaaraLugeja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaksumaaraNimetaja!=null) {
                Writer.WriteStartElement("maksumaara_nimetaja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.MaksumaaraNimetaja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKpv!=null) {
                Writer.WriteStartElement("algus_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.AlgusKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKpv!=null) {
                Writer.WriteStartElement("lopp_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.LoppKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Liikmed!=null) {
                Writer.WriteStartElement("liikmed");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("detailandmed_hy_liige", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Liikmed.Count);
                for (int x = 0; ((clazz.Liikmed != null) 
                            && (x < clazz.Liikmed.Count)); x = (x + 1)) {
                    if (clazz.Liikmed[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaLiikmed = this.GetMetaData(clazz.Liikmed[x]);
                        Writer.WriteTypeAttribute(metaLiikmed.TypeQualifiedName.Namespace, metaLiikmed.TypeQualifiedName.Name);
                        metaLiikmed.NewSerializer(clazz.Liikmed[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.Kitsendused!=null) {
                Writer.WriteStartElement("kitsendused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("detailandmed_hy_kitsendus", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Kitsendused.Count);
                for (int x = 0; ((clazz.Kitsendused != null) 
                            && (x < clazz.Kitsendused.Count)); x = (x + 1)) {
                    if (clazz.Kitsendused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaKitsendused = this.GetMetaData(clazz.Kitsendused[x]);
                        Writer.WriteTypeAttribute(metaKitsendused.TypeQualifiedName.Namespace, metaKitsendused.TypeQualifiedName.Name);
                        metaKitsendused.NewSerializer(clazz.Kitsendused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="liikmesuse_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>liikmesuse_nr");
                }
                clazz.LiikmesuseNr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("liikmesuse_nr")).Value;
            }
            if (Reader.LocalName=="pindala") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>pindala");
                }
                clazz.Pindala = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("pindala")).Value;
            }
            if (Reader.LocalName=="maksumaara_lugeja") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>maksumaara_lugeja");
                }
                clazz.MaksumaaraLugeja = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("maksumaara_lugeja")).Value;
            }
            if (Reader.LocalName=="maksumaara_nimetaja") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>maksumaara_nimetaja");
                }
                clazz.MaksumaaraNimetaja = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("maksumaara_nimetaja")).Value;
            }
            if (Reader.LocalName=="algus_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>algus_kpv");
                }
                clazz.AlgusKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("algus_kpv")).Value;
            }
            if (Reader.LocalName=="lopp_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>lopp_kpv");
                }
                clazz.LoppKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("lopp_kpv")).Value;
            }
            if (Reader.LocalName=="liikmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>liikmed");
                }
                clazz.Liikmed = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyLiige>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("liikmed");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hy_liikmed>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaLiikmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyLiige>(Reader, "detailandmed_hy_liige", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyLiige item = metaLiikmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyLiige>();
                        clazz.Liikmed.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaLiikmed.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="kitsendused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hooneyhistu_liige>kitsendused");
                }
                clazz.Kitsendused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyKitsendus>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kitsendused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_hy_kitsendused>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaKitsendused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyKitsendus>(Reader, "detailandmed_hy_kitsendus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyKitsendus item = metaKitsendused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedHyKitsendus>();
                        clazz.Kitsendused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaKitsendused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
